package org.particles.domain.sim;

import java.util.List;

import org.particles.common.CommonUtil;
import org.particles.domain.field.StringForce;
import org.particles.domain.world.FieldRepository;

public class StringSimulation extends AbstractSimulationCase {
	public static final int PARAM_REJ_STRENGTH = CommonUtil.uniqueIndex();
	public static final int PARAM_ATTR_STRENGTH = CommonUtil.uniqueIndex();
	public static final int PARAM_MAX_LENGTH = CommonUtil.uniqueIndex();
	public static final int PARAM_MIN_LENGTH = CommonUtil.uniqueIndex();
	protected StringForce stringForce;

	public StringSimulation() {
		super();
		setName("String force");
		setWorldWidth(800);
		setWorldHeight(600);
		setNumberParticles(40);
		setFieldMarkers(FieldRepository.STRING);
		setMaxParticleImpulse(3);
		setParticleRadius(6);
		
		stringForce = (StringForce) getFieldRepository().getField(FieldRepository.STRING);
		stringForce.setRejStrength(1);
		stringForce.setAttrStrength(0.5);
		stringForce.setMaxLength(10);
		stringForce.setMinLength(10);
	}

	@Override
	public boolean changeParam(int paramCode, double newValue) {
		if(super.changeParam(paramCode, newValue)) {
			return true;
		}
		else {
			if(PARAM_REJ_STRENGTH == paramCode) {
				stringForce.setRejStrength(newValue);
				return true;
			}
			if(PARAM_ATTR_STRENGTH == paramCode) {
				stringForce.setAttrStrength(newValue);
				return true;
			}
			if(PARAM_MAX_LENGTH == paramCode) {
				stringForce.setMaxLength(newValue);
				return true;
			}
			if(PARAM_MIN_LENGTH == paramCode) {
				stringForce.setMinLength(newValue);
				return true;
			}
			else {
				return false;
			}
		}
	}

	@Override
	public List<SimParam> availableParams() {
		final List<SimParam> params = super.availableParams();
		SimParam param;
		param = new SimParam(
				PARAM_REJ_STRENGTH, 
				"rejection strength", 
				stringForce.getRejStrength());
		param.setMinValue(0D);
		param.setMaxValue(100D);
		params.add(param);
		param = new SimParam(
				PARAM_ATTR_STRENGTH, 
				"attraction strength", 
				stringForce.getAttrStrength());
		param.setMinValue(0D);
		param.setMaxValue(100D);
		params.add(param);
		param = new SimParam(
				PARAM_MAX_LENGTH, 
				"max length", 
				stringForce.getMaxLength());
		param.setMinValue(0D);
		param.setMaxValue(1000D);
		param.setDesc("min length plus this values");
		params.add(param);
		param = new SimParam(
				PARAM_MIN_LENGTH, 
				"min length", 
				stringForce.getMinLength());
		param.setMinValue(0D);
		param.setMaxValue(1000D);
		param.setDesc("distance between particle boundary plus this value");
		params.add(param);
		return params;
	}
}
